from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import get_game
import random

class bush3(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
           
        # build list of actions
        self.add_action(Out)
        self.add_action(Down)
        self.add_action(Shoot_it)
        self.add_action(Hunt)
    
    # return description of room.
    def get_description(self):
        game = get_game()
        if game.history[-2].get_id() == 'lion_pride':
            return "You narrowly escaped with your life! But now an elephant is blocking your path and doesn't look happy you are invading his turf."
        else:
            return "An elephant is blocking your path and doesn't look happy you are invading his turf."
    
    # return image of room
    def get_image(self):
        return 'bush3.jpg'
        
    def gun_has_bullets(self):
        game = get_game()
        player = game.get_player()
        if 'gun' in player.inventory:
            #if player.inventory['gun'].bullets:
            if player.inventory['gun'].bullets >0:
                return True
            else: 
                return False


class Bush3Handler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return bush3

# define actions for this room

class Out(Action):
    def __init__(self):
        Action.__init__(self, "Out")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Walk back to the Lodge"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'bush1'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"


class Down(Action):
    def __init__(self):
        Action.__init__(self, "Down")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Try to slip by"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        if random.randint(1,10)>5:
            return 'victory_room'
        else:
            return 'death'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
class Shoot_it(Action):
    def __init__(self):
        Action.__init__(self, "Shoot_it")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Shoot it"
    
    def is_enabled(self):
        if self.room.gun_has_bullets():
            return True
        else:
            return False
        
    # return id of room to enter when action is complete
    def get_destination(self):
        #update bullet count first
        game = get_game()
        player = game.get_player()
        #player.inventory['gun'].bullets=False
        player.inventory['gun'].bullets=player.inventory['gun'].bullets-1
        return 'death'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

class Hunt(Action):
    def __init__(self):
        Action.__init__(self, "Hunt")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Hunt"
    
    def is_enabled(self):
        if self.room.gun_has_bullets():
            return True
        else:
            return False
        
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'hunt'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"